package com.demo.dune.service;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.demo.dune.dao.IMemberRepository;
import com.demo.dune.domain.Member;
import com.demo.dune.domain.MemberVO;

/**
 * MemberService.
 * @author Allen
 * @version 1.0 2022-04-03
 */
@Service
public class MemberService {

    @Autowired
    private IMemberRepository memberRepository;
    
    /**
     * findByCode.
     * @param code
     * @return MemberVO
     */
    public MemberVO findByCode(String code) {
    	Member member = memberRepository.findByCode(code);
    	if (member == null) {
    		return null;
    	}
    	MemberVO memberVO = new MemberVO();
    	BeanUtils.copyProperties(member, memberVO);
        return memberVO;
    }
    
    /**
     * findByName.
     * @param name
     * @return MemberVO
     */
    public MemberVO findByName(String name) {
    	Member member = memberRepository.findByName(name);
    	if (member == null) {
    		return null;
    	}
    	MemberVO memberVO = new MemberVO();
    	BeanUtils.copyProperties(member, memberVO);
        return memberVO;
    }

    /**
     * save.
     * @param memberVO
     */
    public void save(MemberVO memberVO) {
    	Member member = new Member();
    	BeanUtils.copyProperties(memberVO, member);		
    	memberRepository.save(member);
    }
    
}
